home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / BibTeX 1.06 FAT.sit / BibTeX ƒ / Source code / CBibTeXApp.cp < prev    next >
Text File  |  1996-05-31  |  51KB  |  1,021 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. * Product:    Bibtex                                                      *
  4. * Class:      CBibtexApp                                                  *
  5. * Superclass: LDocApplication                                             *
  6. * File:       CBibTeXApp.cp                                               *
  7. * Abstract:   This file overrides the standard PowerPlant application to  *
  8. *             provide the features that we need for Bibtex.               *
  9. * History:                                                                *
  10. *     1.0MI   by Rick Zaccone for MakeIndex                                  *
  11. *     1.0     1-Feb-96   VMD.  Initial version - basically a global       *
  12. *                        replacement of Rick's 'Makeindex' with 'BibTeX'  *
  13. *                                                                         *
  14. **************************************************************************/
  15.  
  16. /* There is some old stuff in here from Makeindex which needs tidying up */
  17.  
  18. #include "CBibTeXApp.h"
  19. #include "BibTeXConstants.h"
  20. #include "BibTeXApp.h"
  21. #include "StdPrefsLib.h"
  22.  
  23. #include <LEditField.h>
  24. #include <LGrowZone.h>
  25. #include <LWindow.h>
  26. #include "bibutils.h"
  27. #include <PP_Messages.h>
  28. #include <PP_Resources.h>
  29. #include <PPobClasses.h>
  30. #include <string.h>
  31. #include <UDrawingState.h>
  32. #include <UMemoryMgr.h>
  33. #include <URegistrar.h>
  34.  
  35. // Static data members:
  36.  
  37. FileFilterUPP   CBibtexApp::sGetBtxFileFilter = NULL;
  38. TEHandle        CBibtexApp::sTextEditH;
  39. LTextEdit       *CBibtexApp::sTextEditPane;
  40.  
  41. #undef __profile__
  42.  
  43. #ifdef __profile__
  44. #include <profiler.h>
  45. #pragma profile off
  46.  
  47. #endif
  48.  
  49. CBibtexApp* theAppPointer;
  50.  
  51. /**************************************************************************
  52. *                                                                         *
  53. * Function:   main                                                        *
  54. * Purpose:    Initializes the heap, the toolbox and installs a grow zone  *
  55. *             function.  Finally, it creates an application object and    *
  56. *             then runs it.                                               *
  57. * Inputs:     None.                                                       *
  58. * Outputs:    None.                                                       *
  59. * Exceptions: None.                                                       *
  60. * Side Effects:   Creates the application object.                         *
  61. * Errors:     None.                                                       *
  62. * History:                                                                *
  63. *     1.0     17-Jul-95   RJZ.  Initial version.                          *
  64. *                                                                         *
  65. **************************************************************************/
  66. void main(void) {
  67.     #ifdef __profile__
  68.     ProfilerInit(collectDetailed, bestTimeBase, 100, 10);
  69.     #endif
  70.  
  71.                                         // See UDebugging.h for how these
  72.                                         // macros work.  Use PP_DebugHeaders68K
  73.                                         // in the C/C++ Language panel when
  74.                                         // debugging and to see error alerts.
  75.                                         // Use PP_ClassHeaders68K when done
  76.                                         // debugging.
  77.     SetDebugThrow_(debugAction_Alert);
  78.     SetDebugSignal_(debugAction_Alert);
  79. //    SetDebugThrow_(debugAction_Nothing);
  80. //    SetDebugSignal_(debugAction_Nothing);
  81.  
  82.                                         // Initialize Memory Manager.
  83.                                         // Parameter is number of Master
  84.                                         // Pointer blocks to allocate
  85.     InitializeHeap(3);
  86.                                         // Initialize standard Toolbox managers
  87.     UQDGlobals::InitializeToolbox(&qd);
  88.                                         // Install a GrowZone function to catch
  89.                                         // low memory situations.
  90.     new LGrowZone(20000);
  91.     
  92.     CBibtexApp theApp;
  93.     // so we can get events from outside calls
  94.     theAppPointer = &theApp;
  95.     theApp.Run();
  96. }
  97.  
  98. /**************************************************************************
  99. *                                                                         *
  100. * Method:     CBibtexApp                                                 *
  101. * Purpose:    This is the constructor for the application object.  It     *
  102. *             performs some initialization.  If a preferences file        *
  103. *             exists, it reads it.                                        *
  104. * Inputs:     None.                                                       *
  105. * Outputs:    None.                                                       *
  106. * Exceptions: None.                                                       *
  107. * Side Effects:   Registers all relevant PowerPlant classes.              *
  108. * Errors:     None.                                                       *
  109. * History:                                                                *
  110. *     1.0     17-Jul-95   RJZ.  Initial version.                          *
  111. *     1.0.1   27-Oct-95   RJZ.  Make the UPP a static data member.        *
  112. *     2.0      6-Feb-96      VMD.  For BibTeX                                                                    *
  113. *                                                                         *
  114. **************************************************************************/
  115. CBibtexApp::CBibtexApp() {
  116.     Boolean         debugOn;
  117.     OSErr           err;
  118.     short           fileRefNum;
  119.  
  120.                                         // Register functions to create core
  121.                                         // PowerPlant classes
  122.     //URegistrar::RegisterClass(LButton::class_ID,        LButton::CreateButtonStream);
  123.     URegistrar::RegisterClass(LCaption::class_ID,        (ClassCreatorFunc)LCaption::CreateCaptionStream);
  124.     URegistrar::RegisterClass(LDialogBox::class_ID,        (ClassCreatorFunc)LDialogBox::CreateDialogBoxStream);
  125.     //URegistrar::RegisterClass(LEditField::class_ID,        LEditField::CreateEditFieldStream);
  126.     //URegistrar::RegisterClass(LListBox::class_ID,        LListBox::CreateListBoxStream);
  127.     //URegistrar::RegisterClass(LPane::class_ID,            LPane::CreatePaneStream);
  128.     //URegistrar::RegisterClass(LPicture::class_ID,        LPicture::CreatePictureStream);
  129.     //URegistrar::RegisterClass(LPlaceHolder::class_ID,    LPlaceHolder::CreatePlaceHolderStream);
  130.     //URegistrar::RegisterClass(LPrintout::class_ID,        LPrintout::CreatePrintoutStream);
  131.     //URegistrar::RegisterClass('prto',                    LPrintout::CreateOldPrintoutStream);
  132.     URegistrar::RegisterClass(LScroller::class_ID,        (ClassCreatorFunc)LScroller::CreateScrollerStream);
  133.     //URegistrar::RegisterClass(LStdControl::class_ID,    LStdControl::CreateStdControlStream);
  134.     URegistrar::RegisterClass(LStdButton::class_ID,        (ClassCreatorFunc)LStdButton::CreateStdButtonStream);
  135.     URegistrar::RegisterClass(LStdCheckBox::class_ID,    (ClassCreatorFunc)LStdCheckBox::CreateStdCheckBoxStream);
  136.     //URegistrar::RegisterClass(LStdRadioButton::class_ID,LStdRadioButton::CreateStdRadioButtonStream);
  137.     //URegistrar::RegisterClass(LStdPopupMenu::class_ID,    LStdPopupMenu::CreateStdPopupMenuStream);
  138.     URegistrar::RegisterClass(LTextEdit::class_ID,        (ClassCreatorFunc)LTextEdit::CreateTextEditStream);
  139.     //URegistrar::RegisterClass(LView::class_ID,            LView::CreateViewStream);
  140.     URegistrar::RegisterClass(LWindow::class_ID,        (ClassCreatorFunc)LWindow::CreateWindowStream);
  141.  
  142.     //URegistrar::RegisterClass(LRadioGroup::class_ID,    LRadioGroup::CreateRadioGroupStream);
  143.     //URegistrar::RegisterClass(LTabGroup::class_ID,        LTabGroup::CreateTabGroupStream);
  144.  
  145.     //URegistrar::RegisterClass(LCicnButton::class_ID,    LCicnButton::CreateCicnButtonStream);
  146.     //URegistrar::RegisterClass(LOffscreenView::class_ID,    LOffscreenView::CreateOffscreenViewStream);
  147.     //URegistrar::RegisterClass(LActiveScroller::class_ID,LActiveScroller::CreateActiveScrollerStream);
  148.     //URegistrar::RegisterClass(LTable::class_ID,            LTable::CreateTableStream);
  149.     //URegistrar::RegisterClass(LIconPane::class_ID,        LIconPane::CreateIconPaneStream);
  150.     //URegistrar::RegisterClass(LGroupBox::class_ID,        LGroupBox::CreateGroupBoxStream);
  151.     //URegistrar::RegisterClass(LTextButton::class_ID,    LTextButton::CreateTextButtonStream);
  152.     
  153.     //RegisterAllPPClasses();
  154.                                         // no btx file yet
  155.     mGotBtxFile = false;
  156.     mLogWindow = NULL;
  157.     sGetBtxFileFilter = NewFileFilterProc((ProcPtr) GetBtxFileFilter);
  158.     ThrowIfMemError_();
  159.     err = ::OneTimeInitialization();
  160.     ThrowIfOSErr_(err);
  161.                                         // If the preferences file exists, read
  162.                                         // it and set the appropriate variables
  163.                                         // accordingly.
  164.  
  165.     mPrefsFileExists = PreferencesFileExists(kDummyCreator, kDummyType);
  166.     if (mPrefsFileExists) {
  167.         err = OpenPreferencesFile(kDummyCreator, kDummyType, &fileRefNum);
  168.         if (err == noErr) {
  169.             ReadBooleanPref(debugOn,        myBLID_Debug,        fileRefNum);
  170.             ReadBooleanPref(mGoOnOpen,      myBLID_GoOnOpen,     fileRefNum);
  171.             ReadBooleanPref(mAutoQuit,      myBLID_AutoQuit,     fileRefNum);
  172.             ReadBooleanPref(mBigBibTeX,     myBLID_BigBibTeX,     fileRefNum);
  173.             SetBibtexOptions(debugOn);
  174.             err = ClosePreferencesFile(fileRefNum);
  175.         } else
  176.             ReportOSErr("Error trying to open preferences file: %s", err);
  177.  
  178.                                         // If the preferences file doesn¥'t
  179.                                         // exist, use the default values for Go
  180.                                         // On Open and Auto Quit.
  181.     } else {
  182.         mGoOnOpen = kGoOnOpenDefault;
  183.         mAutoQuit = kAutoQuitDefault;
  184.         mBigBibTeX = false;
  185.     }
  186. }
  187.  
  188. /*********************************************************************
  189. *                                                                    *
  190. * Method:     ~CBibtexApp                                           *
  191. * Purpose:    Destructor for the application object.  It doesn't do  *
  192. *             anything yet.                                          *
  193. * Inputs:     None.                                                  *
  194. * Outputs:    None.                                                  *
  195. * Exceptions: None.                                                  *
  196. * Side Effects:   None.                                              *
  197. * Errors:     None.                                                  *
  198. * History:                                                           *
  199. *     1.0     17-Jul-95   RJZ.  Initial version.                     *
  200. *                                                                    *
  201. *********************************************************************/
  202. CBibtexApp::~CBibtexApp(void) {
  203. }
  204.  
  205. /************************************************************************
  206. *                                                                       *
  207. * Method:     StartUp                                                   *
  208. * Purpose:    This function lets you do something when the application  *
  209. *             starts up.  For example, you could issue your own New     *
  210. *             command.                                                  *
  211. * Inputs:     None.                                                     *
  212. * Outputs:    None.                                                     *
  213. * Exceptions: None.                                                     *
  214. * Side Effects:   None.                                                 *
  215. * Errors:     None.                                                     *
  216. * History:                                                              *
  217. *     1.0     17-Jul-95   RJZ.  Initial version.                        *
  218. *                                                                       *
  219. ************************************************************************/
  220. void CBibtexApp::StartUp(void) {
  221.  
  222. }
  223.  
  224. /**************************************************************************
  225. *                                                                         *
  226. * Method:     ObeyCommand                                                 *
  227. * Purpose:    Obeys commands for this application.  If the command is     *
  228. *             not a Bibtex specific command, call the overridden       *
  229. *             ObeyCommand.                                                *
  230. * Inputs:     inCommand is the command to be obeyed.  If the command is   *
  231. *             sent as a result of a menu selection, the ioParam           *
  232. *             parameter is an Int32*. The value is the result returned    *
  233. *             by MenuSelect or MenuKey, which has the MENU ID in the hi   *
  234. *             word and the menu item number in the lo word.  This allows  *
  235. *             you to use a "real" command number rather than relying on   *
  236. *             synthetic command numbers for menu choices that depend on   *
  237. *             the text of the menu item. For example, a Font or Size      *
  238. *             menu.                                                       *
  239. * Outputs:    ioParam may be an output parameter.  See the Inputs         *
  240. *             section.                                                    *
  241. * Exceptions: None.                                                       *
  242. * Side Effects:   Creates the Bibtex log window.                       *
  243. * Errors:     None.                                                       *
  244. * History:                                                                *
  245. *     1.0     17-Jul-95   RJZ.  Initial version.                          *
  246. *     1.0.1   23-Oct-95   RJZ.  Changed the default so that it calls      *
  247. *                         ObeyCommand for LDocApplication.  This allowed  *
  248. *                         me to get rid of the processing for cmd_Open.   *
  249. *                                                                         *
  250. **************************************************************************/
  251. Boolean CBibtexApp::ObeyCommand(CommandT inCommand, void *ioParam) {
  252.     Boolean     cmdHandled = true;
  253.  
  254.     switch (inCommand) {
  255.  
  256.     case cmd_Go:
  257.         ResetWindow();
  258.         ::InvokeBibtex();
  259.         if (mAutoQuit)
  260.             ObeyCommand(cmd_Quit, NULL);
  261.         break;
  262.  
  263.     case cmd_OpenOptionsDialog:
  264.         OpenOptionsDialog();
  265.         break;
  266.  
  267.     case cmd_SetOptions:
  268.         SetDialogOptions((SDialogResponse *) ioParam);
  269.         break;
  270.  
  271.     case cmd_SaveSettings:
  272.         DoSaveSettings();
  273.         break;
  274.  
  275.     default:
  276.         cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  277.         break;
  278.     }
  279.  
  280.     return cmdHandled;
  281. }
  282.  
  283. /**************************************************************************
  284. *                                                                         *
  285. * Method:     FindCommandStatus                                           *
  286. * Purpose:    Pass back whether a menu Command is enabled and/or marked.  *
  287. * Inputs:     inCommand is a menu command number.                         *
  288. * Outputs:    outEnabled indicates if it is enabled, outUsesMark          *
  289. *             indicates if it is marked, outMark is the mark.  outName    *
  290. *             is the new name for the menu item.                          *
  291. * Exceptions: None.                                                       *
  292. * Side Effects:   None.                                                   *
  293. * Errors:     None.                                                       *
  294. * History:                                                                *
  295. *     1.0     17-Jul-95   RJZ.  Initial version.                          *
  296. *     1.0.1   23-Oct-95   RJZ.  The default case should call              *
  297. *                         LDocApplication::FindCommandStatus().           *
  298. *                                                                         *
  299. **************************************************************************/
  300. void CBibtexApp::FindCommandStatus(CommandT inCommand,
  301.                                     Boolean  &outEnabled,
  302.                                     Boolean  &outUsesMark,
  303.                                     Char16   &outMark,
  304.                                     Str255   outName)
  305. {
  306.     switch (inCommand) {
  307.                                         // Return menu item status according to
  308.                                         // command messages.  Any that you
  309.                                         // don't handle will be passed to
  310.                                         // LDocApplication
  311.     case cmd_New:
  312.         outEnabled = false;             // disable the New command
  313.         outUsesMark = false;
  314.         break;
  315.                                         // The Open command is available if
  316.                                         // there is no window open and the
  317.                                         // preferences dialog is not open.
  318.     case cmd_Open:
  319.         outEnabled = !UDesktop::FrontWindowIsModal() && mLogWindow == NULL;
  320.         break;
  321.                                         // The Close command is enabled if the
  322.                                         // front window is not modal and there
  323.                                         // is a log window open.
  324.     case cmd_Close:
  325.     case cmd_Go:
  326.         outEnabled = !UDesktop::FrontWindowIsModal() && mLogWindow != NULL;
  327.         break;
  328.                                         // The Options... command is available
  329.                                         // as long as the options dialog isn't
  330.                                         // already being displayed.  PowerPlant
  331.                                         // will probably do this automatically
  332.                                         // in a future version.  Same for Save
  333.                                         // command.
  334.     case cmd_OpenOptionsDialog:
  335.     case cmd_SaveSettings:
  336.     case cmd_Quit:
  337.         outEnabled = !UDesktop::FrontWindowIsModal();
  338.         break;
  339.  
  340.     default:
  341.         LDocApplication::FindCommandStatus(inCommand, outEnabled,
  342.                                         outUsesMark, outMark, outName);
  343.         break;
  344.     }
  345. }
  346.  
  347. /**********************************************************************
  348. *                                                                     *
  349. * Method:     CBibtexApp::DisplayInLogWindow (static)                *
  350. * Purpose:    Displays text in the log window.                        *
  351. * Inputs:     inMessage is a pointer to a string to be displayed.     *
  352. *             inSize is the size of the string.                       *
  353. * Outputs:    None.                                                   *
  354. * Exceptions: None.                                                   *
  355. * Side Effects:   Changes the contents of the Log Window.             *
  356. * Design:     Just uses toolbox routines to insert text into the log  *
  357. *             window.                                                 *
  358. * Errors:     None.                                                   *
  359. * History:                                                            *
  360. *     1.0     28-Jul-95   RJZ.  Initial version.                      *
  361. *                                                                     *
  362. **********************************************************************/
  363. void CBibtexApp::DisplayInLogWindow(char *inMessage, Int32 inSize) {
  364.     for(short i=0;i<strlen(inMessage);i++){
  365.         if (inMessage[i] == '¥n')
  366.             inMessage[i] = '¥r';
  367.     }
  368.     ::TEInsert(inMessage, inSize, sTextEditH);
  369.     ::TECalText(sTextEditH);
  370.     sTextEditPane->AdjustImageToText();
  371. }
  372.  
  373. /************************************************************************
  374. *                                                                       *
  375. * Method:     CBibtexApp::PostErrorAlert (static)                      *
  376. * Purpose:    Displays an error Alert.                                  *
  377. * Inputs:     inMessage is a pointer to a Pascal style string to be     *
  378. *             displayed.                                                *
  379. * Outputs:    None.                                                     *
  380. * Exceptions: None.                                                     *
  381. * Side Effects:   Displays an alert.                                    *
  382. * Design:     Deactivate and activate the desktop.  It doesn't seem to  *
  383. *             be necessary, but all the example programs do it!         *
  384. * Errors:     None.                                                     *
  385. * History:                                                              *
  386. *     1.0     28-Jul-95   RJZ.  Initial version.                        *
  387. *                                                                       *
  388. ************************************************************************/
  389. void CBibtexApp::PostErrorAlert(StringPtr inMessage) {
  390.  
  391.     ::ParamText(inMessage, "¥p", "¥p", "¥p");
  392.     UDesktop::Deactivate();
  393.     (void) ::Alert(ALRT_OSErr, NULL);
  394.     UDesktop::Activate();
  395. }
  396.  
  397. /*************************************************************************
  398. *                                                                        *
  399. * Method:     CBibtexApp::OpenOptionsDialog                             *
  400. * Purpose:    Opens the options dialog.  Initializes the items in the    *
  401. *             dialog to reflect the current program settings.            *
  402. * Inputs:     None.                                                      *
  403. * Outputs:    None.                                                      *
  404. * Exceptions: None.                                                      *
  405. * Side Effects:   Displays a dialog.                                     *
  406. * Errors:     None.                                                      *
  407. * History:                                                               *
  408. *     1.0     28-Jul-95   RJZ.  Initial version.                         *
  409. *     1.0.1   30-Nov-95   RJZ.  Use dynamic_cast to cast pointers.  Use  *
  410. *                         Assert_ to assure that it worked.              *
  411. *                                                                        *
  412. *************************************************************************/
  413. void CBibtexApp::OpenOptionsDialog(void) {
  414.     LStdCheckBox    *checkBox;
  415.     Boolean         debugOn;
  416.     LDialogBox      *theDialog;
  417.     LUndoer         *undoer;
  418.  
  419.                                         // Create the dialog
  420.  
  421.     theDialog = (LDialogBox *) LWindow::CreateWindow(PPob_OptionsDialog, this);
  422.  
  423.                                         // make typing undoable
  424.     undoer = new LUndoer;
  425.     theDialog->AddAttachment(undoer);
  426.                                         // Get current Bibtex settings
  427.  
  428.     ::GetBibtexOptions(debugOn);
  429.  
  430.  
  431.                                         // Initialize debug box
  432.  
  433.     checkBox = dynamic_cast<LStdCheckBox *>
  434.         (theDialog->FindPaneByID(paneID_Debug));
  435.     Assert_(checkBox != NULL);
  436.     checkBox->SetValue(debugOn);
  437.                                         // Initialize Auto Quit option
  438.  
  439.     checkBox = dynamic_cast<LStdCheckBox *>
  440.         (theDialog->FindPaneByID(paneID_AutoQuit));
  441.     Assert_(checkBox != NULL);
  442.     checkBox->SetValue(mAutoQuit);
  443.                                         // Initialize Go On Open option
  444.  
  445.     checkBox = dynamic_cast<LStdCheckBox *>
  446.         (theDialog->FindPaneByID(paneID_GoOnOpen));
  447.     Assert_(checkBox != NULL);
  448.     checkBox->SetValue(mGoOnOpen);
  449.  
  450.     checkBox = dynamic_cast<LStdCheckBox *>
  451.         (theDialog->FindPaneByID(paneID_BigBibTeX));
  452.     Assert_(checkBox != NULL);
  453.     checkBox->SetValue(mBigBibTeX);
  454.  
  455.     theDialog->Show();
  456. }
  457.  
  458. /*************************************************************************
  459. *                                                                        *
  460. * Method:     CBibtexApp::SetDialogOptions                              *
  461. * Purpose:    This function gets invoked when the user hits the OK       *
  462. *             button.  It extracts the selections the user has made and  *
  463. *             sets Bibtex variables accordingly.                      *
  464. * Inputs:     inPresponse is a pointer to a SDialogResponse structure.   *
  465. * Outputs:    None.                                                      *
  466. * Exceptions: None.                                                      *
  467. * Side Effects:   May change the value of some instance variables.       *
  468. * Errors:     None.                                                      *
  469. * History:                                                               *
  470. *     1.0     28-Jul-95   RJZ.  Initial version.                         *
  471. *     1.0.1   30-Nov-95   RJZ.  Use dynamic_cast to cast pointers.       *
  472. *                         Assert_ that it worked.                        *
  473. *                                                                        *
  474. *************************************************************************/
  475. void CBibtexApp::SetDialogOptions(SDialogResponse *inResponse) {
  476.     LStdCheckBox    *checkBox;
  477.     Boolean         debugOn;
  478.  
  479.                                         // Get value of debug box
  480.  
  481.     checkBox = dynamic_cast<LStdCheckBox *>
  482.         (inResponse->dialogBox->FindPaneByID(paneID_Debug));
  483.     Assert_(checkBox != NULL);
  484.     debugOn = checkBox->GetValue();
  485.                                         // Get value of auto quit box
  486.  
  487.     checkBox = dynamic_cast<LStdCheckBox *>
  488.         (inResponse->dialogBox->FindPaneByID(paneID_AutoQuit));
  489.     Assert_(checkBox != NULL);
  490.     mAutoQuit = checkBox->GetValue();
  491.                                         // Get value of Go On Open box
  492.  
  493.     checkBox = dynamic_cast<LStdCheckBox *>
  494.         (inResponse->dialogBox->FindPaneByID(paneID_GoOnOpen));
  495.     Assert_(checkBox != NULL);
  496.     mGoOnOpen = checkBox->GetValue();
  497.  
  498.     checkBox = dynamic_cast<LStdCheckBox *>
  499.         (inResponse->dialogBox->FindPaneByID(paneID_BigBibTeX));
  500.     Assert_(checkBox != NULL);
  501.     mBigBibTeX = checkBox->GetValue();
  502.     // Set options
  503.  
  504.     ::SetBibtexOptions(debugOn);
  505.  
  506.                                         // Delete the dialog box
  507.     delete inResponse->dialogBox;
  508. }
  509.  
  510. /**************************************************************************
  511. *                                                                         *
  512. * Method:     CBibtexApp::AllowSubRemoval                                *
  513. * Purpose:    The window object invokes this method before closing the    *
  514. *             Log Window.  This allows us to do any cleaning up we need   *
  515. *             to do.                                                      *
  516. * Inputs:     inSub (I forget what it's for!)                             *
  517. * Outputs:    Returns true indicating that it's OK to close the window.   *
  518. * Exceptions: None.                                                       *
  519. * Side Effects:   Sets mLogWindow to indicate that the log window is no   *
  520. *             longer visible.  Also closes any files that might be open.  *
  521. * Errors:     None.                                                       *
  522. * History:                                                                *
  523. *     1.0     28-Jul-95   RJZ.  Initial version.                          *
  524. *                                                                         *
  525. **************************************************************************/
  526. Boolean CBibtexApp::AllowSubRemoval(LCommander *inSub) {
  527. #pragma unused (inSub)
  528.  
  529.     mLogWindow = NULL;
  530.     ::CloseAllFiles();
  531.  
  532.     return true;
  533. }
  534.  
  535. /************************************************************************
  536. *                                                                       *
  537. * Method:     CBibtexApp::MakeNewDocument                              *
  538. * Purpose:    This function gets invoked if the user wants to create a  *
  539. *             new document.  This is not a feature we support.          *
  540. * Inputs:     None.                                                     *
  541. * Outputs:    Just return NULL.                                         *
  542. * Exceptions: None.                                                     *
  543. * Side Effects:   None.                                                 *
  544. * Errors:     None.                                                     *
  545. * History:                                                              *
  546. *     1.0     28-Jul-95   RJZ.  Initial version.                        *
  547. *                                                                       *
  548. ************************************************************************/
  549. LModelObject *CBibtexApp::MakeNewDocument(void) {
  550.  
  551.     return NULL;
  552. }
  553.  
  554. /**************************************************************************
  555. *                                                                         *
  556. * Method:     CBibtexApp::ChooseDocument                                 *
  557. * Purpose:    Asks the user to select a document to open.  We filter the  *
  558. *             names so that only text files that end in ".aux" are        *
  559. *             shown.  If the user makes a selection, open the file.       *
  560. * Inputs:     None.                                                       *
  561. * Outputs:    None.                                                       *
  562. * Exceptions: None.                                                       *
  563. * Side Effects:   Displays a standard open file dialog on the screen.     *
  564. * Errors:     None.                                                       *
  565. * History:                                                                *
  566. *     1.0     28-Jul-95   RJZ.  Initial version.                          *
  567. *     1.0.1   27-Oct-95   RJZ.  Make the UPP a static data member.        *
  568. *                                                                         *
  569. **************************************************************************/
  570. void CBibtexApp::ChooseDocument(void) {
  571.     StandardFileReply   reply;
  572.     SFTypeList          typeList;
  573.  
  574.     typeList[0] = 'TEXT';
  575.     UDesktop::Deactivate();
  576.     ::StandardGetFile(sGetBtxFileFilter, 1, typeList, &reply);
  577.     UDesktop::Activate();
  578.     if (reply.sfGood)
  579.         OpenDocument(&reply.sfFile);
  580. }
  581.  
  582. /*************************************************************************
  583. *                                                                        *
  584. * Function:   CBibtexApp::GetBtxFileFilter (static)                     *
  585. * Purpose:    Filters file names for StandardGetFile so that the user    *
  586. *             will see only names that end in .aux.                      *
  587. * Inputs:     pb is a pointer to an information block for the name of a  *
  588. *             file that StandardGetFile is considering to display.       *
  589. * Outputs:    True if StandardGetFile should filter the file (not        *
  590. *             display it), false to display the file.                    *
  591. * Exceptions: None.                                                      *
  592. * Side Effects:   Affects which files are displayed by StandardGetFile.  *
  593. * Design:     If the file name is longer than 4 characters, assume that  *
  594. *             the last 4 characters contain an extension.                *
  595. * Errors:     None.                                                      *
  596. * History:                                                               *
  597. *     1.0     10-Jul-95   RJZ.  Initial version.                         *
  598. *     1.0.1   27-Oct-95   RJZ.  This is now a static member function.    *
  599. *                                                                        *
  600. *************************************************************************/
  601. pascal Boolean CBibtexApp::GetBtxFileFilter(CInfoPBPtr pb) {
  602.     char        *extensionPtr;
  603.     Boolean     filter;
  604.     StringPtr   name;
  605.  
  606.     name = pb->hFileInfo.ioNamePtr;
  607.     extensionPtr = (char *) name + StrLength(name) - 3;
  608.     if (StrLength(name) > 4 && strncmp(extensionPtr, BIBTEX_INP, 4) == 0)
  609.         filter = false;
  610.     else
  611.         filter = true;
  612.  
  613.     return filter;
  614. }
  615.  
  616. /**************************************************************************
  617. *                                                                         *
  618. * Method:     CBibtexApp::OpenDocument                                   *
  619. * Purpose:    Performs all processing associated with opening a           *
  620. *             document.  It tells Bibtex about the file.  If a window  *
  621. *             is already open, it clears out the text and changes the     *
  622. *             window title.  If no window is open, it creates a new one   *
  623. *             and displays it.                                            *
  624. * Inputs:     inMacFSSpec is a pointer to the FSSpec record of the file   *
  625. *             to be opened.                                               *
  626. * Outputs:    None.                                                       *
  627. * Exceptions: None.                                                       *
  628. * Side Effects:   Initializes some instance variables such as             *
  629. *             mGotBtxFile, mLogWindow, sTextEditPane, and sTextEditH.     *
  630. * Errors:     None.                                                       *
  631. * History:                                                                *
  632. *     1.0     28-Jul-95   RJZ.  Initial version.                          *
  633. *                                                                         *
  634. **************************************************************************/
  635. void CBibtexApp::OpenDocument(FSSpec *inMacFSSpec) {
  636.     ::CloseAllFiles();
  637.     ::IntroduceBtxFile(inMacFSSpec);
  638.     mGotBtxFile = true;
  639.     if (mGoOnOpen) {
  640.         ObeyCommand(cmd_Go, NULL);
  641.     } else {
  642.         ResetWindow();
  643.     }
  644. }
  645.  
  646. /* Separated this from above function so 'Go' can call it too */
  647. /* VMD May31st 1996 */
  648.  
  649. void CBibtexApp::ResetWindow(void){
  650.     Str255      windowTitle;
  651.     if (mLogWindow != NULL) {
  652.         ::TESetSelect(0L, 32767L, sTextEditH);
  653.         ::TEDelete(sTextEditH);
  654.         ::GetWindowTitle(windowTitle);
  655.         mLogWindow->SetDescriptor(windowTitle);
  656.         mLogWindow->Refresh();
  657.     } else {
  658.         mLogWindow = LWindow::CreateWindow(PPob_EditWindow, this);
  659.         ::GetWindowTitle(windowTitle);
  660.         mLogWindow->SetDescriptor(windowTitle);
  661.         mLogWindow->Show();
  662.         sTextEditPane = (LTextEdit *)
  663.                         mLogWindow->FindPaneByID(paneID_TextEdit);
  664.         sTextEditH = sTextEditPane->GetMacTEH();
  665.     }
  666. }
  667.  
  668. /***********************************************************************
  669. *                                                                      *
  670. * Method:     CBibtexApp::DoSaveSettings                              *
  671. * Purpose:    This function gets invoked when the user selects Save    *
  672. *             Current Settings from the Options menu.  It saves the    *
  673. *             current settings in the preferences file.  If the        *
  674. *             preferences file doesn't exist, it creates it.           *
  675. * Inputs:     None.                                                    *
  676. * Outputs:    None.                                                    *
  677. * Exceptions: None.                                                    *
  678. * Side Effects:   Write the current settings to the preferences file.  *
  679. *             May also create a preferences file.                      *
  680. * Errors:     None.                                                    *
  681. * History:                                                             *
  682. *     1.0     28-Jul-95   RJZ.  Initial version.                       *
  683. *                                                                      *
  684. ***********************************************************************/
  685. void CBibtexApp::DoSaveSettings(void) {
  686.     Boolean         debugOn;
  687.     OSErr           err;
  688.     short           fileRefNum;
  689.  
  690.     if (!mPrefsFileExists)
  691.         CreatePrefsFile();
  692.                                         // Get current Bibtex settings
  693.     if (mPrefsFileExists) {
  694.         ::GetBibtexOptions(debugOn);
  695.         err = ::OpenPreferencesFile(kDummyCreator, kDummyType, &fileRefNum);
  696.         if (err == noErr) {
  697.             WriteBooleanPref(debugOn,        myBLID_Debug,        fileRefNum);
  698.             WriteBooleanPref(mGoOnOpen,      myBLID_GoOnOpen,     fileRefNum);
  699.             WriteBooleanPref(mAutoQuit,      myBLID_AutoQuit,     fileRefNum);
  700.             WriteBooleanPref(mBigBibTeX,      myBLID_BigBibTeX,     fileRefNum);
  701.             err = ::ClosePreferencesFile(fileRefNum);
  702.         } else
  703.             ::ReportOSErr("Error trying to open preferences file: %s", err);
  704.     }
  705. }
  706.  
  707. /**************************************************************************
  708. *                                                                         *
  709. * Method:     CBibtexApp::CreatePrefsFile                                *
  710. * Purpose:    Creates a preferences file.                                 *
  711. * Inputs:     None.                                                       *
  712. * Outputs:    None.                                                       *
  713. * Exceptions: None.                                                       *
  714. * Side Effects:   Creates a preferences file.                             *
  715. * Design:     This function uses the StdPrefsLib to do all the right      *
  716. *             things.  It follows the guidelines in Develop 18's article  *
  717. *             "The Right Way to Implement Preferences Files."  It even    *
  718. *             creates two vers resources for the file and inserts the     *
  719. *             application-missing resource ('STR ' -16397).               *
  720. * Errors:     Posts an alert if there are any troubles creating the       *
  721. *             file.                                                       *
  722. * History:                                                                *
  723. *     1.0     28-Jul-95   RJZ.  Initial version.                          *
  724. *                                                                         *
  725. **************************************************************************/
  726. void CBibtexApp::CreatePrefsFile(void) {
  727.     Str255          companyStr = kCompanyString;
  728.     OSErr           err;
  729.     short           fileRefNum;
  730.     Str255          fileSetStr = kFileSetString;
  731.     NumVersion      numVersion;
  732.     short           regionCode;
  733.     Str255          versNumStr = kVersNumString;
  734.  
  735.     err = ::NewPreferencesFile(kDummyCreator, kDummyType,
  736.                                kPrefFileName, NULL, kIdentString);
  737.     if (err == noErr) {
  738.         mPrefsFileExists = true;
  739.         numVersion.majorRev = kMajorRevision;
  740.         numVersion.minorAndBugRev = kMinorAndBugRevision;
  741.         numVersion.stage = kStage;
  742.         numVersion.nonRelRev = kNonReleaseRevision;
  743.         regionCode = ::GetScriptManagerVariable(smRegionCode);
  744.         err = ::OpenPreferencesFile(kDummyCreator, kDummyType, &fileRefNum);
  745.     }
  746.                                         // Set the contents of the vers 1
  747.                                         // resource
  748.     if (err == noErr)
  749.         err = ::SetPreferencesFileVersion(fileRefNum, kVers1, &numVersion,
  750.                                           regionCode, versNumStr, companyStr);
  751.  
  752.                                         // Set the contents of the vers 2
  753.                                         // resource
  754.     if (err == noErr)
  755.         err = ::SetPreferencesFileVersion(fileRefNum, kVers2, &numVersion,
  756.                                           regionCode, versNumStr, fileSetStr);
  757.  
  758.                                         // Post an alert if error
  759.     if (err != noErr)
  760.         ::ReportOSErr("Error trying to create Preferences file: %s", err);
  761.  
  762.                                         // Close prefs file
  763.  
  764.     err = ::ClosePreferencesFile(fileRefNum);
  765. }
  766.  
  767. /*************************************************************************
  768. *                                                                        *
  769. * Method:     CBibtexApp::WriteBooleanPref                              *
  770. * Purpose:    Writes a Boolean preference to the preferences file.       *
  771. *             Boolean preferences are stored in myBL resources.          *
  772. * Inputs:     inValue is the value to be saved.  inID the the id of the  *
  773. *             myBL resource to use.                                      *
  774. * Outputs:    None.                                                      *
  775. * Exceptions: None.                                                      *
  776. * Side Effects:   Writes to the preferences file.                        *
  777. * Errors:     Posts an alert if there was trouble writing.               *
  778. * History:                                                               *
  779. *     1.0     28-Jul-95   RJZ.  Initial version.                         *
  780. *                                                                        *
  781. *************************************************************************/
  782. void CBibtexApp::WriteBooleanPref(Boolean  inValue,
  783.                                    short    inID,
  784.                                    short    inFileRefNum)
  785. {
  786.     OSErr   err = noErr;
  787.     Handle  prefHandle;
  788.     short   resID;
  789.  
  790.     resID = inID;
  791.                                         // Create a handle for our preference
  792.                                         // data
  793.  
  794.     prefHandle = ::NewHandle(sizeof(char));
  795.     if (prefHandle == NULL)
  796.         err = ::MemError();
  797.                                         // Set the contents of the preference
  798.                                         // data
  799.     if (err == noErr) {
  800.         **((char **) prefHandle) = inValue;
  801.  
  802.                                         // Write the preference data to prefs
  803.                                         // file
  804.  
  805.         err = ::WritePreference(inFileRefNum, 'myBL', &resID, prefHandle);
  806.     }
  807.                                         // Post an alert if error
  808.     if (err != noErr)
  809.         ::ReportOSErr("Error trying to write Preferences file: %s", err);
  810.  
  811.                                         // clean up
  812.     ::DisposeHandle(prefHandle);
  813. }
  814.  
  815. /**************************************************************************
  816. *                                                                         *
  817. * Method:     CBibtexApp::WriteLongPref                                  *
  818. * Purpose:    Writes a long preference to the preferences file            *
  819. * Inputs:     inValue is the value to be written.  inID is the id of the  *
  820. *             myLN resource to use.                                       *
  821. * Outputs:    None.                                                       *
  822. * Exceptions: None.                                                       *
  823. * Side Effects:   Writes to the preferences file.                         *
  824. * Errors:     Posts an alert if there is an error.                        *
  825. * History:                                                                *
  826. *     1.0     28-Jul-95   RJZ.  Initial version.                          *
  827. *                                                                         *
  828. **************************************************************************/
  829. void CBibtexApp::WriteLongPref(long    inValue,
  830.                                 short   inID,
  831.                                 short   inFileRefNum)
  832. {
  833.     OSErr   err = noErr;
  834.     Handle  prefHandle;
  835.     short   resID;
  836.  
  837.     resID = inID;
  838.                                         // Create a handle for our preference
  839.                                         // data
  840.  
  841.     prefHandle = ::NewHandle(sizeof(long));
  842.     if (prefHandle == NULL)
  843.         err = ::MemError();
  844.                                         // Set the contents of the preference
  845.                                         // data
  846.     if (err == noErr) {
  847.         **((long **) prefHandle) = inValue;
  848.  
  849.                                         // Write the preference data to prefs
  850.                                         // file
  851.  
  852.         err = ::WritePreference(inFileRefNum, 'myLN', &resID, prefHandle);
  853.     }
  854.                                         // Post an alert if error
  855.     if (err != noErr)
  856.         ::ReportOSErr("Error trying to write Preferences file: %s", err);
  857.  
  858.                                         // clean up
  859.     ::DisposeHandle(prefHandle);
  860. }
  861.  
  862. /*************************************************************************
  863. *                                                                        *
  864. * Method:     CBibtexApp::WriteStringPref                               *
  865. * Purpose:    Writes a string preference to the preferences file.        *
  866. * Inputs:     inValue is a pointer to a Pascal style string to be        *
  867. *             written.  It may be any length up to 255.  inID is the id  *
  868. *             of the myST resource to use.                               *
  869. * Outputs:    None.                                                      *
  870. * Exceptions: None.                                                      *
  871. * Side Effects:   Writes to the preferences file.                        *
  872. * Errors:     Posts an alert if there is an error.                       *
  873. * History:                                                               *
  874. *     1.0     28-Jul-95   RJZ.  Initial version.                         *
  875. *                                                                        *
  876. *************************************************************************/
  877. void CBibtexApp::WriteStringPref(StringPtr inValue,
  878.                                   short     inID,
  879.                                   short     inFileRefNum)
  880. {
  881.     Size    byteCount;
  882.     OSErr   err = noErr;
  883.     Handle  prefHandle;
  884.     short   resID;
  885.  
  886.     resID = inID;
  887.                                         // Create a handle for our preference
  888.                                         // data
  889.  
  890.     prefHandle = ::NewHandleClear(sizeof(Str255));
  891.     if (prefHandle == NULL)
  892.         err = ::MemError();
  893.                                         // Set the contents of the preference
  894.                                         // data.  It¥'s probably not necessary
  895.                                         // to lock the handle.  Be safe though.
  896.     if (err == noErr) {
  897.         byteCount = inValue[0] + 1;
  898.         ::HLock(prefHandle);
  899.         ::BlockMoveData(inValue, *prefHandle, byteCount);
  900.         ::HUnlock(prefHandle);
  901.                                         // Write the preference data to prefs
  902.                                         // file
  903.  
  904.         err = ::WritePreference(inFileRefNum, 'myST', &resID, prefHandle);
  905.     }
  906.                                         // Post an alert if error
  907.     if (err != noErr)
  908.         ::ReportOSErr("Error trying to write Preferences file: %s", err);
  909.  
  910.                                         // clean up
  911.     ::DisposeHandle(prefHandle);
  912. }
  913.  
  914. /*********************************************************************
  915. *                                                                    *
  916. * Method:     CBibtexApp::ReadBooleanPref                           *
  917. * Purpose:    Reads a Boolean preference from the preferences file.  *
  918. * Inputs:     inID is the id of the myBL resource to read.           *
  919. * Outputs:    outValue is the value of the resource.                 *
  920. * Exceptions: None.                                                  *
  921. * Side Effects:   None.                                              *
  922. * Errors:     Posts an alert if there is an error.                   *
  923. * History:                                                           *
  924. *     1.0     28-Jul-95   RJZ.  Initial version.                     *
  925. *                                                                    *
  926. *********************************************************************/
  927. void CBibtexApp::ReadBooleanPref(Boolean&  outValue,
  928.                                   short     inID,
  929.                                   short     inFileRefNum)
  930. {
  931.     OSErr   err;
  932.     Handle  prefHandle;
  933.     short   resID;
  934.  
  935.     resID = inID;
  936.                                         //  Read the resource
  937.  
  938.     err = ::ReadPreference(inFileRefNum, 'myBL', &resID, &prefHandle);
  939.  
  940.                                         // Post an alert if error
  941.     if (err != noErr)
  942.         ::ReportOSErr("Error trying to read Preferences file: %s", err);
  943.  
  944.     outValue = **prefHandle != 0;
  945.     ::DisposeHandle(prefHandle);
  946. }
  947.  
  948. /***************************************************************
  949. *                                                              *
  950. * Method:     CBibtexApp::ReadLongPref                        *
  951. * Purpose:    Reads a long value from a myLN resource.         *
  952. * Inputs:     inID is the id of the myLN resource to read.     *
  953. * Outputs:    outValue is the value read.                      *
  954. * Exceptions: None.                                            *
  955. * Side Effects:   None.                                        *
  956. * Errors:     Posts an alert if there is any trouble reading.  *
  957. * History:                                                     *
  958. *     1.0     28-Jul-95   RJZ.  Initial version.               *
  959. *                                                              *
  960. ***************************************************************/
  961. void CBibtexApp::ReadLongPref(long&    outValue,
  962.                                short    inID,
  963.                                short    inFileRefNum)
  964. {
  965.     OSErr   err;
  966.     Handle  prefHandle;
  967.     short   resID;
  968.  
  969.     resID = inID;
  970.                                         //  Read the resource
  971.  
  972.     err = ::ReadPreference(inFileRefNum, 'myLN', &resID, &prefHandle);
  973.  
  974.                                         // Post an alert if error
  975.     if (err != noErr)
  976.         ::ReportOSErr("Error trying to read Preferences file: %s", err);
  977.  
  978.     outValue = **((long **) prefHandle);
  979.     ::DisposeHandle(prefHandle);
  980. }
  981.  
  982. /*******************************************************************
  983. *                                                                  *
  984. * Method:     CBibtexApp::ReadStringPref                          *
  985. * Purpose:    Reads a string preference from the preference file.  *
  986. * Inputs:     inID is the id of the myST resource to read.         *
  987. * Outputs:    outValue points to the value read.                   *
  988. * Exceptions: None                                                 *
  989. * Side Effects:   None.                                            *
  990. * Errors:     Posts an alert if there is a read error.             *
  991. * History:                                                         *
  992. *     1.0     28-Jul-95   RJZ.  Initial version.                   *
  993. *                                                                  *
  994. *******************************************************************/
  995. void CBibtexApp::ReadStringPref(StringPtr  outValue,
  996.                                  short      inID,
  997.                                  short      inFileRefNum)
  998. {
  999.     Size    byteCount;
  1000.     OSErr   err;
  1001.     Handle  prefHandle;
  1002.     short   resID;
  1003.  
  1004.     resID = inID;
  1005.                                         //  Read the resource
  1006.  
  1007.     err = ::ReadPreference(inFileRefNum, 'myST', &resID, &prefHandle);
  1008.  
  1009.                                         // Post an alert if error
  1010.     if (err != noErr)
  1011.         ::ReportOSErr("Error trying to read Preferences file: %s", err);
  1012.  
  1013.     ::HLock(prefHandle);
  1014.     byteCount = **prefHandle + 1;
  1015.     ::BlockMoveData(*prefHandle, outValue, byteCount);
  1016.  
  1017.     ::DisposeHandle(prefHandle);
  1018. }
  1019.  
  1020. #pragma profile reset
  1021.